/**
 *
 * @author davethedev@googlmail.com
 */

package nethelp.gui;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import nethelp.network.NetworkInterfaceTableModel;

public class MainFrame extends javax.swing.JFrame {

    /** Creates new form MainFrame */
    public MainFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tabPane = new javax.swing.JTabbedPane();
        informationTab = new javax.swing.JPanel();
        lblHostName = new javax.swing.JLabel();
        hostName = new javax.swing.JLabel();
        lblIPAddress = new javax.swing.JLabel();
        ipAddress = new javax.swing.JLabel();
        lblOperatingSystem = new javax.swing.JLabel();
        operatingSystem = new javax.swing.JLabel();
        lblUserName = new javax.swing.JLabel();
        userName = new javax.swing.JLabel();
        networkTab = new javax.swing.JPanel();
        networkTableScrollPane = new javax.swing.JScrollPane();
        networkTable = new javax.swing.JTable();
        btnRefresh = new javax.swing.JButton();
        aboutTab = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        lblHostName.setText("Host name:");

        hostName.setText("...");

        lblIPAddress.setText("IP Address:");

        ipAddress.setText("...");

        lblOperatingSystem.setText("Operating System:");

        operatingSystem.setText("...");

        lblUserName.setText("User name:");

        userName.setText("...");

        org.jdesktop.layout.GroupLayout informationTabLayout = new org.jdesktop.layout.GroupLayout(informationTab);
        informationTab.setLayout(informationTabLayout);
        informationTabLayout.setHorizontalGroup(
            informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(informationTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, lblUserName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, lblOperatingSystem, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(lblIPAddress, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(lblHostName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(operatingSystem)
                    .add(ipAddress)
                    .add(hostName)
                    .add(userName))
                .addContainerGap(241, Short.MAX_VALUE))
        );
        informationTabLayout.setVerticalGroup(
            informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(informationTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblHostName)
                    .add(hostName))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblIPAddress)
                    .add(ipAddress))
                .add(18, 18, 18)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblOperatingSystem)
                    .add(operatingSystem))
                .add(18, 18, 18)
                .add(informationTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(lblUserName)
                    .add(userName))
                .addContainerGap(189, Short.MAX_VALUE))
        );

        initializeInformationTab();

        tabPane.addTab("Information", informationTab);

        networkTable.setModel(new NetworkInterfaceTableModel());
        networkTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        networkTableScrollPane.setViewportView(networkTable);

        btnRefresh.setText("Refresh");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout networkTabLayout = new org.jdesktop.layout.GroupLayout(networkTab);
        networkTab.setLayout(networkTabLayout);
        networkTabLayout.setHorizontalGroup(
            networkTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(networkTableScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, networkTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(btnRefresh))
        );
        networkTabLayout.setVerticalGroup(
            networkTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(networkTabLayout.createSequentialGroup()
                .add(networkTableScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 281, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btnRefresh))
        );

        tabPane.addTab("Network", networkTab);

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 48)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(255, 0, 51));
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("NetHelp");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 204));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("version 0.1");

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Developed by davethedev@googlemail.com 2008");

        org.jdesktop.layout.GroupLayout aboutTabLayout = new org.jdesktop.layout.GroupLayout(aboutTab);
        aboutTab.setLayout(aboutTabLayout);
        aboutTabLayout.setHorizontalGroup(
            aboutTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(aboutTabLayout.createSequentialGroup()
                .addContainerGap()
                .add(aboutTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .add(jLabel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE)
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 366, Short.MAX_VALUE))
                .addContainerGap())
        );
        aboutTabLayout.setVerticalGroup(
            aboutTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(aboutTabLayout.createSequentialGroup()
                .add(44, 44, 44)
                .add(jLabel2)
                .add(18, 18, 18)
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel3)
                .addContainerGap(94, Short.MAX_VALUE))
        );

        tabPane.addTab("About", aboutTab);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(tabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(tabPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        networkTable.setModel(new NetworkInterfaceTableModel());
    }//GEN-LAST:event_btnRefreshActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        try {
            // Set the default platform l & f
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainFrame().setVisible(true);
            }
        });
    }

    private void initializeInformationTab() {
        try {
            InetAddress addr = InetAddress.getLocalHost();
            hostName.setText(addr.getHostName());
            ipAddress.setText(addr.getHostAddress());
        } catch (UnknownHostException e) {
            hostName.setText("<<unknown>>");
            ipAddress.setText("<<unknown>>");
        }

        String osName = System.getProperty("os.name");
        String osVersion = System.getProperty("os.version");
        operatingSystem.setText(osName + " " + osVersion);

        String un = System.getProperty("user.name");
        userName.setText(un);

    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel aboutTab;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JLabel hostName;
    private javax.swing.JPanel informationTab;
    private javax.swing.JLabel ipAddress;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel lblHostName;
    private javax.swing.JLabel lblIPAddress;
    private javax.swing.JLabel lblOperatingSystem;
    private javax.swing.JLabel lblUserName;
    private javax.swing.JPanel networkTab;
    private javax.swing.JTable networkTable;
    private javax.swing.JScrollPane networkTableScrollPane;
    private javax.swing.JLabel operatingSystem;
    private javax.swing.JTabbedPane tabPane;
    private javax.swing.JLabel userName;
    // End of variables declaration//GEN-END:variables
}
